package Algorithm.Othes;
// https://leetcode-cn.com/problems/projection-area-of-3d-shapes/
public class Leetcode883_三维形体投影面积 {
    class Solution {
        public int projectionArea(int[][] grid) {
            int topArea = 0;
            int frontArea = 0;
            int leftArea = 0;

            int n = grid.length;

            for(int i = 0; i < n; i++){
                int maxFront = 0;
                int maxLeft = 0;
                for(int j = 0; j < n; j++){
                    maxFront = Math.max(maxFront, grid[i][j]);
                    maxLeft = Math.max(maxLeft, grid[j][i]);
                    if (grid[i][j] > 0){
                        topArea ++;
                    }
                }

                frontArea += maxFront;
                leftArea += maxLeft;
            }

            int sum = topArea + leftArea + frontArea;
            return sum;
        }
    }
}
